package com.zkingsoft.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.util.ResponseUtils;

/**
 * @description 全局异常处理类
 * @author 姜友瑶
 * @data 2016-06-26
 */
@Service("com.zkingsoft.exception.GlobleExceptionResolver")
public class GlobleExceptionResolver implements HandlerExceptionResolver {

	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		GlobleException globleException = null;
		AjaxResult result = null;
		if (ex instanceof GlobleException) {
			globleException = (GlobleException) ex;
			result = new AjaxResult(AjaxResult.STATUS_ERR, null, globleException.getMessage());
		} else {
			ex.printStackTrace();
			result = new AjaxResult(AjaxResult.STATUS_UNKWON_ERR, null, "系统出现错误请稍后再试！错误信息：" + ex.getMessage());
		}
		ResponseUtils.send(response, result);
		return null;
	}

}
